#include "QFileInfeSorterFactory.h"
#include "FunctionInterpreter.h"
#include <qdir.h>
#include <qdatetime.h>
#include <QDebug>



bool MyFileInfo::operator< (const MyFileInfo &t2) const{
    qDebug() << d->m_code;
    switch (d->m_code) {
    case 1:
        qDebug() << d->info.fileName() << t2.d->info.fileName();
        return (d->info.fileName() < t2.d->info.fileName());
    case 2:
        qDebug() << d->info.created() << t2.d->info.created();
        return (d->info.created() < t2.d->info.created());
    case 3:
        qDebug() << d->info.lastModified() << t2.d->info.lastModified();
        return (d->info.lastModified() < t2.d->info.lastModified());
    case 4:
        qDebug() << d->info.size() << t2.d->info.size();
        return (d->info.size() < t2.d->info.size());
    case 5:
        qDebug() << d->info.dir().dirName() << t2.d->info.dir().dirName();
        return (d->info.dir().dirName() < t2.d->info.dir().dirName());
    case 6: {
        if(!d->v.isValid()){
            FunctionInterpreter interpret;
            bool bOk = true;
            QVariant vTmp = interpret.interpretFunction("parseDateReg", QVariantList() << d->info.dir().dirName() << d->param, bOk);
            if(bOk){
                d->v = vTmp;
            }else{
                qDebug() << "Error this" << vTmp;
                d->v = 0;
            }
        }
        if(!t2.d->v.isValid()){
            FunctionInterpreter interpret;
            bool bOk = true;
            QVariant vTmp = interpret.interpretFunction("parseDateReg", QVariantList() << t2.d->info.dir().dirName() << d->param, bOk);
            if(bOk){
                t2.d->v = vTmp;
            }else{
                qDebug() << "Error this" << vTmp;
                t2.d->v = 0;
            }
        }
        qDebug() << d->v << t2.d->v;
        return d->v.toDateTime() < t2.d->v.toDateTime();
    }
    default:
        qDebug() << d->info.absoluteFilePath() << t2.d->info.absoluteFilePath();
        return (d->info.absoluteFilePath() < t2.d->info.absoluteFilePath());
    }
}


QFileInfeSorterFactory::QFileInfeSorterFactory()
{
}

QStringList QFileInfeSorterFactory::getSorterDescriptions(){
    QStringList list;
    list << QString("le chemin absolue");
    list << QString("le nom");
    list << QString("la date de création");
    list << QString("la date de modification");
    list << QString("la taille");
    list << QString("le nom du dossier");
    list << QString("le nom du dossier en date");

    return list;
}

qLess<MyFileInfo>* QFileInfeSorterFactory::getSorterByIdx(const int& idx, const QString& param){
    qLess<MyFileInfo>* sorter = NULL;
    return sorter;
}
